#!/usr/bin/env python
# -*- coding: utf-8 -*-
###########################################################################
#   Copyright (C) 2008 by Serj Poltavsky                                  #
#   serge.uliss at gmail.com                                              #
#                                                                         #
#   This program is free software; you can redistribute it and/or modify  #
#   it under the terms of the GNU General Public License as published by  #
#   the Free Software Foundation; either version 3 of the License, or     #
#   (at your option) any later version.                                   #
#                                                                         #
#   This program is distributed in the hope that it will be useful,       #
#   but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#   GNU General Public License for more details.                          #
#                                                                         #
#   You should have received a copy of the GNU General Public License     #
#   along with this program. If not, see <http://www.gnu.org/licenses/>   #
###########################################################################

import unittest
from spumux import SpumuxStream
from xml.dom import minidom

class TestSpumuxStream(unittest.TestCase):
    def setUp(self):
        self.spumuxstream = SpumuxStream()

    def test_init(self):
        self.assertEqual(self.spumuxstream.nodename, 'stream')
        self.assertEqual(self.spumuxstream.force, False)
        self.assertEqual(self.spumuxstream.image, None)
        self.assertEqual(self.spumuxstream.image_highlight, None)
        self.assertEqual(self.spumuxstream.image_select, None)
        self.assertEqual(self.spumuxstream.start, 0)
        self.assertEqual(self.spumuxstream.end, 0)

        self.spumuxstream.start = 10
        self.assertEqual(self.spumuxstream.start, 10)

    def test_update(self):
        dom = minidom.Document()
        sstr = self.spumuxstream.update(dom, dom)
        self.assert_(len(sstr.childNodes) > 0)
        spu = dom.getElementsByTagName('spu')

        self.assert_(len(spu))
        self.assertEqual(spu[0].getAttribute('force'), 'no')
        self.assert_(not spu[0].hasAttribute('select'))
        self.assert_(not spu[0].hasAttribute('image'))
        self.assert_(not spu[0].hasAttribute('highlight'))

        self.spumuxstream.force = True
        self.spumuxstream.image = 'image'
        self.spumuxstream.image_select = 'select'
        self.spumuxstream.image_highlight = 'highlight'
        self.spumuxstream.start = 11.1
        self.spumuxstream.end = 111.1

        dom = minidom.Document()
        sstr = self.spumuxstream.update(dom, dom)
        self.assert_(len(sstr.childNodes) > 0)
        spu = dom.getElementsByTagName('spu')

        self.assertEqual(spu[0].getAttribute('force'), 'yes')
        self.assertEqual(spu[0].getAttribute('image'), 'image')
        self.assertEqual(spu[0].getAttribute('select'), 'select')
        self.assertEqual(spu[0].getAttribute('highlight'), 'highlight')
        self.assertEqual(spu[0].getAttribute('start'), '00:00:11.10')
        self.assertEqual(spu[0].getAttribute('end'), '00:01:51.10')
